package neusoft.yuejian_11.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.squareup.picasso.Picasso;

import java.util.List;

import neusoft.yuejian_11.activity.AllPostDatilActivity;
import neusoft.yuejian_11.base.BaseListAdapter;
import neusoft.yuejian_11.bean.PostCollectBean;
import neusoft.yuejian_11.R;
import neusoft.yuejian_11.viewHolder.PostCollectViewHolder;

import static neusoft.yuejian_11.interF.Const.BASE_URI;

/**
 * Created by NEUSOFT on 2017/10/19.
 */

public class PostCollectAdapter extends BaseListAdapter {
    public PostCollectAdapter(Context context, List data) {
        super(context, data);
    }
    @Override
    protected RecyclerView.ViewHolder onCreateVH(ViewGroup parent, LayoutInflater layoutInflater, int viewType) {
        View itemView=layoutInflater.inflate(R.layout.item_postcollect,parent,false);
        PostCollectViewHolder holder=new PostCollectViewHolder(itemView);
        return holder;
    }

    @Override
    protected void onBindVH(RecyclerView.ViewHolder holder, List data, int position) {
        PostCollectViewHolder postCollectViewHolder=(PostCollectViewHolder) holder;
        final PostCollectBean postCollectBean = (PostCollectBean)data.get(position);
        final int postId =postCollectBean.getP_id();
        final String postTitle =postCollectBean.getP_title();
        String postpic = BASE_URI+"pphoto/"+postCollectBean.getP_pic();
        Picasso.with(context)
                .load(postpic)
                .into(PostCollectViewHolder.imageView);
        postCollectViewHolder.posttitleView.setText(postTitle);

        //从收藏列表跳到详情
        postCollectViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, AllPostDatilActivity.class);
                intent.putExtra("p_id",postId);
                context.startActivity(intent);

            }
        });
    }

}
